import 'dart:convert';
import 'package:audioplayers/audioplayers.dart';
import 'package:dio/dio.dart';
import 'dart:io';

class ServerConfig {
  String os_url = "https://dict.youdao.com";
}

class XHttp {
  //发起网络请求
  netWorkRequest({
    Map? header,
    Map? param, //参数
  }) async {
    // AudioPlayer audioPlayer = AudioPlayer();
    var dio = Dio();
    dio.options.baseUrl = ServerConfig().os_url;
    dio.options.contentType = Headers.formUrlEncodedContentType;
    dio.options.responseType = ResponseType.plain;
    dio.options.connectTimeout = 5000; //5s
    dio.options.receiveTimeout = 3000;
    var response = await dio.request(
      "/dictvoice",
      data: param,
      options: Options(
        method: "POST",
      ),
    );
    if (response != null) {
      // print(response.toString());
      // audioPlayer
      //     .play("https://dict.youdao.com/dictvoice?audio=collection&type=1");
      print("有数据了");
    } else {}
  }
}
